{extend name="property/public/insidePageBase" /}
{block name="title"}添加房源{/block}
{block name="body"}
<div class="layuimini-container">
    <div class="layuimini-main">
        <div class="layui-form layui-form-pane">
            <div class="layui-row">
                <div class="layui-col-xs6">
                    <div class="layui-form-item">
                        <label class="layui-form-label">物业筛选</label>
                        <div class="layui-input-block">
                            <select name="property_id" lay-filter="property_id" lay-search>
                                <option value="">--请选择--</option>
                                {foreach $propertyData as $v}
                                <option value="{$v['id']}" {if ($info['property_id'] == $v['id'])}selected{/if}>{$v['name']}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs6">
                    <div class="layui-form-item">
                        <label class="layui-form-label indispensable">门店名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="store_name" value="{$info['store_name']??''}" placeholder="请输入(10-25个字)" class="layui-input" lay-verify="required" autocomplete="off"/>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-row">
                <div class="layui-col-xs6">
                    <div class="layui-input-group" id="work_time">
                        <div class="layui-input-split layui-input-prefix indispensable">&nbsp;&nbsp;&nbsp;&nbsp;营业时间&nbsp;&nbsp;&nbsp;&nbsp;</div>
                        <input type="text" autocomplete="off" name="work_start" value="{$info['work_start']??''}" id="work_start" class="layui-input" placeholder="开始时间">
                        <div class="layui-input-split layui-input-suffix">-</div>
                        <input type="text" autocomplete="off" name="work_end" value="{$info['work_end']??''}" id="work_end" class="layui-input" placeholder="结束时间">
                    </div>
                </div>
                <div class="layui-col-xs6">
                    <div class="layui-form-item" pane="">
                        <label class="layui-form-label">门店状态</label>
                        <div class="layui-input-block">
                            <input type="radio" name="is_show" value="1" title="营业中" {:isset($info['is_show']) ? $info['is_show'] == 1 ? 'checked' : '' : ''}/>
                            <input type="radio" name="is_show" value="2" title="歇业中" {:isset($info['is_show']) ? $info['is_show'] == 2 ? 'checked' : '' : ''}/>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-row">
                <div class="layui-col-xs10">
                    <div class="layui-form-item">
                        <label class="layui-form-label indispensable">详细地址</label>
                        <div class="layui-input-block">
                            <input type="text" name="address" id="address"  value="{$info['address']??''}" placeholder="请输入所属地址" class="layui-input" autocomplete="off"/>
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs2">
                    <button class="layui-btn layui-btn-primary layui-border" type="button" id="map_location"><i class="layui-icon layui-icon-location"></i>定位选择</button>
                </div>
            </div>
            <div class="layui-row">
                <div class="layui-col-xs10">
                    <div class="layui-form-item">
                        <label class="layui-form-label">门店标签</label>
                        <div class="layui-input-block">
                            <input type="text" name="label_id" id="label" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs2">
                    <button type="button" class="layui-btn layui-btn-primary layui-border addCarwashLabel"> 添加新标签 </button>
                </div>
            </div>

            <div class="layui-row">
                <div class="layui-col-xs10">
                    <div class="layui-form-item">
                        <label class="layui-form-label indispensable">门店主图</label>
                        <div class="layui-input-block">
                            <input type="text" name="picture" value="{$info['picture']??''}" placeholder="请上传物业图片" id="picture" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs1">
                    <button type="button" class="layui-btn layui-btn-primary uploadImg" lay-data="{field: 'picture',data:{dir:'property/picture', field:'picture'}}">
                        <i class="layui-icon">&#xe67c;</i>
                    </button>
                </div>
                <div class="layui-col-xs1">
                    <img class="checkPictureByImg picture"  value="{$info['picture']??''}" style="width: 38px;height: 38px;">
                </div>
            </div>

            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">备注说明</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入"  name="remark" class="layui-textarea">{$info['remark']??''}</textarea>
                </div>
            </div>

            <div class="layui-form-item layui-hide">
                <input type="hidden" name="longitude" id="longitude" value="{$info['longitude'] ?? ''}" />
                <input type="hidden" name="latitude" id="latitude" value="{$info['latitude'] ?? ''}" />
                <button type="button" class="layui-btn layui-btn-primary replaceUploadImg toggleUpload" lay-data="{}"></button>
                <button class="layui-btn" lay-submit lay-filter="submitBtn" id="submitBtn">提交</button>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="js"}
{__block__}
<script>
    layui.use(['form', 'layer', 'laydate','layCascader'], function () {
        var form = layui.form,layer = layui.layer,  $ = layui.$, layCascader = layui.layCascader, laydate = layui.laydate;
        laydate.render({
            elem: '#work_time'
            ,type: 'time'
            //设置开始日期、日期日期的 input 选择器
            //数组格式为 2.6.6 开始新增，之前版本直接配置 true 或任意分割字符即可
            ,range: ['#work_start', '#work_end']
        });
        let labelCase = layCascader({
            elem: '#label',
            options: {:json_encode($labelData,JSON_UNESCAPED_UNICODE)},
            value: {:json_encode($info['label_ids'],JSON_UNESCAPED_UNICODE)},
            props: {
                multiple: true
            }
        });
        $('.uploadImg').selectImages({
            confirm:function(res,elem,data) {
                $('#' + data.field).val(res[0].src);
                $('.' + data.field).attr('src',res[0].src)
            }
        });

        $('#map_location').on('click', function() {
            parent.layer.open({
                type: 2,
                title: '定位',
                content: "/static/maplocation/index.html",
                area: ['500px', '500px'],
                btn: ['确认','取消'],
                yes: function(index, layero){
                    choseeArea = parent.window.frames['layui-layer-iframe'+index].choseeArea;
                    if(choseeArea === undefined) {
                        return parent.layer.msg('请选择地区');
                    }
                    $('#address').val(choseeArea.regeocode.formattedAddress);
                    $('#latitude').val(choseeArea.lnglat.lat);
                    $('#longitude').val(choseeArea.lnglat.lng);
                    parent.layer.close(index);
                }
            });
        });

        $('.addCarwashLabel').on('click', function() {
            var url = '{:url("propertyCarwashLabelAdd")}';
            var index = parent.layer.open({title: '添加',type: 2,shade: 0.2, maxmin:true,area: ['500px', '400px'], content: url, btnAlign: 'c' , btn: ['确定', '取消'] , yes: function (index, layero) {
                    var iframeWindow = parent.window['layui-layer-iframe' + index] , submit = layero.find('iframe').contents().find("#submitBtn");
                    iframeWindow.layui.form.on('submit(submitBtn)', function (data) {
                        var field = data.field; //获取提交的字段
                        var loadAdd = parent.layer.msg('提交中', {icon: 16, time: 0, shade: 0.1, offset: '15px'});
                        $.post(url, field, function (res) {
                            parent.layer.close(loadAdd);
                            if (res.code === 0) {
                                parent.layer.close(index); //关闭弹层
                                window.location.reload(); //刷新整个页面
                                parent.layer.msg(res.msg, {icon: 6, offset: '15px'});
                            } else {
                                parent.layer.msg(res.msg, {icon: 5, offset: '15px'});
                            }
                        });
                    });
                    submit.trigger('click');
                }
            });
        });

    });
</script>
{/block}